//Requires Model,View and App to be loaded first
//Put Event-handlers and control-flow related stuff here

var gxMenuMemonaut = null;
var gxMenuScrap = null;
var gxMenuBookmarks = null;
var gxMenuClip = null;
var gxMenuNotebookList = null;

memonautMenuItems = [
    { name: 'Hide Note Icons', className: 'edit', callback: Controls_hide},
    { name: 'Numbering On', className: 'edit', callback: Numbering_on},
    { name: 'Show Note Information', className: 'edit', callback: InfoDisplay_show},
    { separator: true},
    { name: 'Show Note Icons', className: 'edit', callback: Controls_show},
    { name: 'Numbering Off', className: 'edit', callback: Numbering_off},
    { name: 'Hide Note Information', className: 'edit', callback: InfoDisplay_hide}
];

scrapMenuItems = [
    { name: 'Add Note', className: 'edit',  callback: addNote },
    { name: 'Edit', className: 'edit',  callback: editScrap },
    { name: 'Export', className: 'edit',  callback: exportNote },
    { name: 'Information', className: 'edit',  callback: toggleScrapInfo },
    { name: 'Bookmark', className: 'edit',  callback: addBookmark},
    { separator: true},
    { name: 'Move Up', className: 'edit',  callback: shiftUpScrap },
    { name: 'Move Down', className: 'edit', callback: shiftDownScrap},
    { separator: true},
    { name: 'Shift Out', className: 'edit', callback: shiftOutScrap},
    { name: 'Shift Into Previous', className: 'edit', callback: shiftIntoPreviousScrap},
    { name: 'Shift Into Next', className: 'edit', callback: shiftIntoNextScrap}
];

bookmarkMenuItems = [
    { name: 'Rename', className: 'edit',  callback:  Bookmark_rename },
    { name: 'Move Up', className: 'edit',  callback:  Bookmark_moveUp },
    { name: 'Move Down', className: 'edit', callback: Bookmark_moveDown},
    { name: 'Delete', className: 'edit',  callback:   Bookmark_delete }
];

clipMenuItems =[
    { name: 'Cut', className: 'edit',  callback:  cutScrap },
    { name: 'Paste', className: 'edit',  callback:   pasteScrap},
    { name: 'Cancel Cut/Copy', className: 'edit',  callback:  cancelClipboard },
    { name: 'Delete', className: 'edit',  callback: deleteScrap},
    { separator: true},
    { name: 'Merge Into Previous', className: 'edit', callback: mergePreviousScrap},
    { name: 'Merge Into Next', className: 'edit', callback: mergeNextScrap},
    { name: 'Merge Into Parent', className: 'edit',  callback: mergeParentScrap }
];

notebookListMenuItems = [
    { name: 'Move Up', className: 'edit',  callback:  Notebook_moveUp },
    { name: 'Move Down', className: 'edit', callback: Notebook_moveDown},
    { name: 'Remove From List', className: 'edit',  callback:   Notebook_remove }
];

function Controller_init()
{
        initMenuMemonaut();
        initShortcuts();
}

function initShortcuts()
{
shortcut.add("Ctrl+Up",CurrentScrap_moveUp,
{'propagate':false,'type':'keydown','target':document});
shortcut.add("Ctrl+Down",CurrentScrap_moveDown,
{'propagate':false,'type':'keydown','target':document});
shortcut.add("Ctrl+Left",CurrentScrap_moveOut,
{'propagate':false,'type':'keydown','target':document});
shortcut.add("Ctrl+Right",CurrentScrap_moveIn,
{'propagate':false,'type':'keydown','target':document});

shortcut.add("Up",CurrentScrap_moveUp,
{disable_in_input: true,'propagate':false,'type':'keydown','target':document});
shortcut.add("Down",CurrentScrap_moveDown,
{disable_in_input: true,'propagate':false,'type':'keydown','target':document});
shortcut.add("Left",CurrentScrap_moveOut,
{disable_in_input: true,'propagate':false,'type':'keydown','target':document});
shortcut.add("Right",CurrentScrap_moveIn,
{disable_in_input: true,'propagate':false,'type':'keydown','target':document});

shortcut.add("Insert",CurrentScrap_addNote,
{disable_in_input: true, 'type':'keydown','propagate':false,'target':document});
shortcut.add("Enter",CurrentScrap_addNext,
{disable_in_input: true,'type':'keydown','propagate':false,'target':document});

shortcut.add("Shift+Right",CurrentScrap_shiftIntoNext,
{disable_in_input: true,'type':'keydown','propagate':false,'target':document});
shortcut.add("Shift+Left",CurrentScrap_shiftIntoPrevious,
{disable_in_input: true,'propagate':false,'type':'keydown','target':document});
shortcut.add("Tab",CurrentScrap_shiftIntoPrevious,
{disable_in_input: true,'propagate':false,'type':'keydown','target':document});
shortcut.add("Shift+Tab",CurrentScrap_shiftOut,
{disable_in_input: true,'type':'keydown','propagate':false,'target':document});
shortcut.add("Shift+Up",CurrentScrap_shiftUp,
{disable_in_input: true,'propagate':false,'type':'keydown','target':document});
shortcut.add("Shift+Down",CurrentScrap_shiftDown,
{disable_in_input: true,'propagate':false,'type':'keydown','target':document});

shortcut.add("Ctrl+Shift+Left",CurrentScrap_mergeParent,
{disable_in_input: true,'type':'keydown','propagate':false,'target':document});
shortcut.add("Ctrl+Shift+Up",CurrentScrap_mergePrevious,
{disable_in_input: true,'propagate':false,'type':'keydown','target':document});
shortcut.add("Ctrl+Shift+Down",CurrentScrap_mergeNext,
{disable_in_input: true,'propagate':false,'type':'keydown','target':document});

shortcut.add("Ctrl+Delete",CurrentScrap_delete,
{disable_in_input: true,'propagate':false,'type':'keydown','target':document});
shortcut.add("F2",CurrentScrap_edit,
{'propagate':false,'type':'keydown','target':document});
shortcut.add("Backspace",CurrentScrap_edit,
{disable_in_input: true,'propagate':false,'type':'keydown','target':document});

shortcut.add("Ctrl+F1",CurrentScrap_info,
{'propagate':false,'type':'keydown','target':document});
shortcut.add("Ctrl+F2",CurrentScrap_bookmark,
{'propagate':false,'type':'keydown','target':document});
shortcut.add("Ctrl+F3",Notepod_setFocus,
{'propagate':false,'type':'keydown','target':document});
shortcut.add("Ctrl+S",saveFile,
{'propagate':false,'type':'keypress','target':document});

shortcut.add("Ctrl+X",CurrentScrap_cut,
{disable_in_input: true,'propagate':true,'type':'keydown','target':document});
shortcut.add("Ctrl+C",CurrentScrap_cut,
{disable_in_input: true,'propagate':false,'type':'keydown','target':document});
shortcut.add("Ctrl+V",CurrentScrap_paste,
{disable_in_input: true,'propagate':true,'type':'keydown','target':document});
shortcut.add("Ctrl+Z", cancelClipboard,
{disable_in_input: true,'propagate':true,'type':'keydown','target':document});

shortcut.add("Delete",CurrentScrap_cut,
{disable_in_input: true,'propagate':false,'type':'keydown','target':document});
shortcut.add("Shift+Delete",CurrentScrap_cut,
{disable_in_input: true,'propagate':false,'type':'keydown','target':document});
shortcut.add("Shift+Insert",CurrentScrap_paste,
{disable_in_input: true,'propagate':false,'type':'keydown','target':document});
}

function initMenuMemonaut(){

	gxMenuMemonaut = new Proto.Menu({
	  selector: '#menuMemonaut',
	  className: 'protomenu firefox',
	  menuItems: memonautMenuItems,
	  activator: 'click'
	});

	gxMenuScrap = new Proto.Menu({
	  selector: '#Scrapbook .clicker',
	  className: 'protomenu firefox',
	  menuItems:  scrapMenuItems,
	  beforeShow:setCurrentScrap,
	  activator: 'click'
	});

        gxMenuBookmarks = new Proto.Menu({
	  selector: '#listBookmarks .iconBookmark',
	  className: 'protomenu firefox',
	  menuItems:  bookmarkMenuItems,
	  activator: 'click'
	});

        gxMenuClip = new Proto.Menu({
	  selector: '#Scrapbook .iconActions',
	  className: 'protomenu firefox',
	  menuItems:  clipMenuItems,
	  beforeShow:setCurrentScrap,
	  activator: 'click'
	});

        gxMenuNotebookList = new Proto.Menu({
	  selector: '#listNotebooks .iconNotebook',
	  className: 'protomenu firefox',
	  menuItems:  notebookListMenuItems,
	  activator: 'click'
	});
}



